package com.niit.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * @author hanli
 * @date 2025/3/6
 * @description TODO
 */
public class MybatisUtil {
    public static SqlSession getSqlSession() {

        SqlSessionFactory sqlSessionFactory =null;
        SqlSession sqlSession = null;
        // 读取配置文件 保存 输入流
        try {
            InputStream inputStream = Resources.getResourceAsStream("config/mybatis-config.xml");

            sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);

            sqlSession = sqlSessionFactory.openSession();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return sqlSession;
    }
}